<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@include file="/pageRc/common/common.jsp"%>

<!DOCTYPE html>
<html lang="en" style="overflow-x: hidden">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport"
	content="initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
<meta name="format-detection" content="telephone=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta name="msapplication-tap-highlight" content="no">

<link rel="stylesheet"
	href="<%=commonPath %>/pageRc/layui/css/layui.css" media="all">
<script type="text/javascript"
	src="<%=commonPath %>/pageRc/js/jquery-1.9.1.min.js"></script>
<link rel="stylesheet"
	href="<%=commonPath %>/pageRc/plugs/ebankLayer/css/ebankLayer.css">
</script>
<script type="text/javascript"
	src="<%=commonPath %>/pageRc/plugs/ebankLayer/js/ebankLayer.js"></script>
<script type="text/javascript"
	src="<%=commonPath %>/pageRc/common/utils.js"></script>
<script type="text/javascript"
	src="<%=commonPath %>/pageRc/common/msgTool.js"></script>
<script type="text/javascript"
	src="<%=commonPath %>/pageRc/layui/layui.js"></script>

<title>商户订单统计</title>

<script>
	$(function(){ 
		var now = new Date();
		//获取当前年月日
		var ymd = now.getFullYear()+""+((now.getMonth()+1)<10?"0":"")+(now.getMonth()+1)+""+(now.getDate()<10?"0":"")+now.getDate();
		var ymd1 = now.getFullYear()+""+((now.getMonth()+1)<10?"0":"")+(now.getMonth()+1)+""+(now.getDate()<10?"0":"")+now.getDate();

		//获取当前时分秒
		$("#startDate").val(ymd);
		$("#endDate").val(ymd1);
		btnStyleByFontColor("bt1"); //按钮 字体样式修改
	})
	//注意：选项卡 依赖 element 模块，否则无法进行功能性操作
	layui.use('element', function() {
		var element = layui.element();

		//…
	});
</script>
</head>
<body class="layui-main">
	<div class="layui-form-item ">
		<form id="createMsgForm" name="createMsgForm" class="layui-form"
			action="">
			<div class="layui-form-item">
				<div class="layui-inline">
					<div class="layui-inline">
						<label class="layui-form-label" style="text-align: left">汇总方式</label>
						<div class="layui-input-block">
							<input type="radio" name="sex" value="0" title="按日期" lay-filter="sumRadio" checked> 
							<input type="radio" name="sex" value="1" title="按项目组" lay-filter="sumRadio">
							<input type="radio" name="sex" value="2" title="按团队" lay-filter="sumRadio">
						</div>
					</div>
					<div class="layui-inline">
						<select name="modules" lay-filter="transactionSumSelect">
							<option value="">报工状态</option>
							<option value="">全部</option>
							<option value="1">已报工</option>
							<option value="0">未报工</option>
						</select>
					</div>
					<div class="layui-inline">
						<select name="modules" lay-filter="zhifuSelect">
							<option value="">开发阶段</option>
							<option value="">全部</option>
							    <option value="01">需求分析</option>
			                    <option value="02">需求评审</option>
			                    <option value="03">技术评审</option>
			                    <option value="04">开发联调</option>
			                    <option value="05">SIT测试</option>
			                    <option value="06">UAT测试</option>
			                    <option value="07">上线</option>
			                    <option value="08">回顾总结</option>
						</select>
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-inline">
					<div class="layui-inline">
						<input class="layui-input" style="width: 200px" id="startDate"
							onclick="layui.laydate({elem: this, istime: true, format: 'YYYYMMDD'})"
							placeholder="开始日期">
					</div>
					<div class="layui-inline">
						<input class="layui-input" style="width: 200px" id="endDate"
							onclick="layui.laydate({elem: this, istime: true, format: 'YYYYMMDD'})"
							placeholder="结束日期">
					</div>
					<div class="layui-inline">
						<button id="bt1"  class="layui-btn layui-btn-primary"
							 type="button" data-method="toDay">今天</button>
						<button id="bt2" class="layui-btn layui-btn-primary" type="button"
							 data-method="yesterDay">昨天</button>
						<button class="layui-btn layui-btn-primary" id="bt3" type="button"
							 data-method="lastdays">最近7天</button>
						<button class="layui-btn layui-btn-primary" id="bt4" type="button"
							 data-method="last30days">最近30天</button>
						<button class="layui-btn" type="button" data-method="doSearchSum">查询</button>
						<button class="layui-btn" type="button" data-method="doExcel">excel下载</button>
					</div>

				</div>
			</div>
			<div class="layui-form-item" id="dateDiv">
				<div class="layui-inline">
					<table class="layui-table" lay-even="" lay-skin="line" style="text-align: center;">
						<colgroup>
							<col width="120">
							<col width="120">
							<col width="120">
							<col width="120">
							<col width="120">
							<col width="150">
							<col width="150">
							<col width="150">
						</colgroup>
						<thead>
							<tr>
								<th>团队名称</th>
								<th>项目组名称</th>
								<th>需求编号</th>
								<th>需求名称</th>
								<th>参与人员</th>
								<th>评估工时</th>
								<th>实时消耗工时</th>
								<th>预计完成工时</th>
							</tr>
						</thead>
						<tbody id="detailDiv1">

						</tbody>
						<script id="tplSrc" type="text/html">
							 {{#  layui.each(d.list, function(index, x){}}
							     <tr >
								   <td>{{x.BizDate==undefined?'':x.BizDate}}</td>
								   <td>{{x.OrderAmount==undefined?'':x.OrderAmount}}</td>
								   <td style="color:#ff4a4a">{{x.PaidAmount==undefined?'':x.PaidAmount}}</td>
							       <td>{{x.DiscountAmount==undefined?'':x.DiscountAmount}}</td>
							       <td>{{x.RepaymentAmount==undefined?'':x.RepaymentAmount}}</td>
							       <td>{{x.FeeAmount==undefined?'':x.FeeAmount}}</td>
 								   <td>{{x.sittleAmount==undefined?'':x.sittleAmount=='.00'?'':x.sittleAmount=='0.00'?'':x.sittleAmount}}</td>
								   <td>{{x.OutputChanName==undefined?"":x.OutputChanName}}</td>
							    </tr>
							{{#  }); }} 
					   </script>
					</table>
				</div>
			</div>
			
			<div class="layui-form-item" id="mendianDiv">
				<div class="layui-inline">
					<table class="layui-table" lay-even="" lay-skin="line" style="text-align: center;">
						<colgroup>
							<col width="150">
							<col width="150">
							<col width="150">
							<col width="150">
							<col width="150">
							<col width="150">
							<col width="150">
							<col width="150">
						</colgroup>
						<thead>
							<tr>
								<th>门店</th>
								<th>订单金额(元)</th>
								<th>支付金额(元)</th>
								<th>优惠金额(元)</th>
								<th>退款金额(元)</th>
								<th>手续费金额(元)</th>
								<th>应结算金额(元)</th>
								<th>支付方式</th>
							</tr>
						</thead>
						<tbody id="detailDiv2">

						</tbody>
						<script id="tplSrc1" type="text/html">
							 {{#  layui.each(d.list, function(index, x){}}
							     <tr >
								   <td >{{x.StoreName==undefined?'':x.StoreName}}</td>
								   <td>{{x.OrderAmount==undefined?'':x.OrderAmount}}</td>
								   <td style="color:#ff4a4a">{{x.PaidAmount==undefined?'':x.PaidAmount}}</td>
							       <td>{{x.DiscountAmount==undefined?'':x.DiscountAmount}}</td>
							       <td>{{x.RepaymentAmount==undefined?'':x.RepaymentAmount}}</td>
 								   <td>{{x.FeeAmount==undefined?'':x.FeeAmount}}</td>
								   <td>{{x.sittleAmount==undefined?'':x.sittleAmount=='.00'?'':x.sittleAmount=='0.00'?'':x.sittleAmount}}</td>
 								   <td>{{x.OutputChanName==undefined?"":x.OutputChanName}}</td>
							    </tr>
							{{#  }); }} 
					   </script>
					</table>
				</div>
			</div>
			<div class="layui-form-item" id="shouyinDiv">
				<div class="layui-inline">
					<table class="layui-table" lay-even="" lay-skin="line" style="text-align: center;">
						<colgroup>
							<col width="100">
							<col width="120">
							<col width="150">
							<col width="150">
							<col width="150">
							<col width="150">
							<col width="150">
							<col width="150">
							<col width="100">
						</colgroup>
						<thead>
							<tr>
								<th>收银员</th>
								<th>门店</th>
								<th>订单金额(元)</th>
								<th>支付金额(元)</th>
								<th>优惠金额(元)</th>
								<th>退款金额(元)</th>
								<th>手续费金额(元)</th>
								<th>应结算金额(元)</th>
								<th>支付方式</th>
							</tr>
						</thead>
						<tbody id="detailDiv3">

						</tbody>
						<script id="tplSrc2" type="text/html">
							 {{#  layui.each(d.list, function(index, x){}}
							     <tr >
							       <td >{{x.StaffName==undefined?'':x.StaffName}}</td>
								   <td>{{x.StoreName==undefined?'':x.StoreName}}</td>
								   <td>{{x.OrderAmount==undefined?'':x.OrderAmount}}</td>
								   <td style="color:#ff4a4a">{{x.PaidAmount==undefined?'':x.PaidAmount}}</td>
							       <td>{{x.DiscountAmount==undefined?'':x.DiscountAmount}}</td>
							       <td>{{x.RepaymentAmount==undefined?'':x.RepaymentAmount}}</td>
								   <td>{{x.FeeAmount==undefined?'':x.FeeAmount}}</td>
								   <td>{{x.sittleAmount==undefined?'':x.sittleAmount=='.00'?'':x.sittleAmount=='0.00'?'':x.sittleAmount}}</td>
								   <td>{{x.OutputChanName==undefined?'':x.OutputChanName}}</td>
							    </tr>
							{{#  }); }} 
					   </script>
					</table>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-inline">
					<div id="laypageDiv"></div>
				</div>

			</div>
		</form>
	</div>
	<input id="bindStat" type="hidden" name="bindStat" value="">
	<input id="zhifuStat" type="hidden" name="zhifuStat" value="">
	<input id="sunRedio" type="hidden" name="sunRedio" value="0">
</body>
<script type="text/javascript">
var path="<%=commonPath%>";
var msg =new msgTool();
layui.use(
		[ 'form', 'layer', 'laytpl', 'laypage','laydate' ],
		function() {
			var $ = layui.jquery, layer = layui.layer; //独立版的layer无需执行这一句
	        var form = layui.form()
	            ,layer = layui.layer
	            ,laypage = layui.laypage
	            ,laytpl = layui.laytpl;
	        
			
			
			//获取结算状态
	        form.on('select(transactionSumSelect)', function(data){//下拉框获取值事件
	        	  $("#bindStat").val(data.value);
	        	});  
	      
		 
			
	        var active = {
	        		doSearchSum:function(){   //搜索
	              	    var totalNum = active.doSearchDetail(1); 
	                		laypage({
	      	                   cont: 'laypageDiv'
	      	                 ,pages:totalNum
	      	                  ,jump: function(obj,first){
	       	                	  if(first!=true){
	      	                	  	active.doSearchDetail(obj.curr); 
	       	                	  }
	      	                   }
	      	                 });  
	                 }
	                 ,doSearchDetail:function(v_curr){ //搜索
	              	   try{ 
	              		var totalNum = 0;
	              	    var startDate=$('#startDate').val();
	              	    var endDate=$('#endDate').val();
	              	    var eCustId=$('#ECustId').val();
	          			var SettleStatus = $("#bindStat").val(); //结算状态
	          			var OutputChan=$('#zhifuStat').val(); //支付方式
	          			var StateType=$('#sunRedio').val();    //统计维度
	          			var getTpl;
	          			if(StateType=="0"){
	          				getTpl = tplSrc.innerHTML;
      					}else if(StateType=="1"){
      						getTpl = tplSrc1.innerHTML;
      					}else if(StateType=="2"){
      						getTpl = tplSrc2.innerHTML;
      					}
	          			if(StateType==""){
	          				StateType="0";	
		              	}
	          			var dataObj = {
	          						//startIndex : v_curr-1,
	          						//pageSize : 10,
	          						ECustId:eCustId,
	          						StartDate:startDate,
	          						EndDate:endDate,
	          						OutputChan:OutputChan,
	          						SettleStatus:SettleStatus,
	          						StateType:StateType
	          					};
	          			var index=layer.load();
	          			msg.sendMsg("/page/main/cashier.do",dataObj,function(data){
	          				laytpl(getTpl).render(data.body, function(html){
	          					if(StateType=="0"){
	          						detailDiv1.innerHTML = html;
	          					}else if(StateType=="1"){
	          						detailDiv2.innerHTML = html;
	          					}else if(StateType=="2"){
	          						detailDiv3.innerHTML = html;
	          					}
	          				});
	          				totalNum = data.body.totalNum;
	          			});
	          			layer.close(index);
	              	   }catch(e){
	              		   
	              	   }
	              	   return totalNum;
	                 },
	                 doExcel:function(){ //导出excel
	                		var startDate=$('#startDate').val();
		              	    var endDate=$('#endDate').val();
		              	    var eCustId=$('#ECustId').val();
		          			var SettleStatus = $("#bindStat").val(); //结算状态
		          			var OutputChan=$('#zhifuStat').val(); //支付方式
		          			var StateType=$('#sunRedio').val();    //统计维度
		          			var getTpl;
		          			if(StateType=="0"){
		          				getTpl = tplSrc.innerHTML;
	      					}else if(StateType=="1"){
	      						getTpl = tplSrc1.innerHTML;
	      					}else if(StateType=="2"){
	      						getTpl = tplSrc2.innerHTML;
	      					}
		          			if(StateType==""){
		          				StateType="0";	
			              	}
		          			var dataObj = {
		          						//startIndex : v_curr-1,
		          						//pageSize : 10,
		          						ECustId:eCustId,
		          						StartDate:startDate,
		          						EndDate:endDate,
		          						OutputChan:OutputChan,
		          						SettleStatus:SettleStatus,
		          						StateType:StateType
		          					};
	      				msg.sendMsg("/page/main/cashierExcel.do",dataObj,function(data){
	       				laytpl(getTpl).render(data.body, function(html){
	       					//detailDiv.innerHTML = html;
	       					window.location.href = path +"/downFile/"+data.body.fileName
	       				});
	       			});  
	      				
	              },
	              toDay:function(){   //今天
	            	
	   	 			var now = new Date();
	   	 		//获取当前年月日
	   	 			var ymd = now.getFullYear()+""+((now.getMonth()+1)<10?"0":"")+(now.getMonth()+1)+""+(now.getDate()<10?"0":"")+now.getDate();
	   	 		//获取当前时分秒
	   	 			$("#startDate").val(ymd);
	   	 			$("#endDate").val(ymd);
	   	 			btnStyleByFontColor("bt1"); //按钮 字体样式修改
	              },
	              yesterDay:function(){  //昨天
	            	  var befroeDate = getBeforeDate(1);
	   	 			  var lastymd = getBeforeDate(1);
	            	  $("#startDate").val(befroeDate);
	   	 			  $("#endDate").val(lastymd);
	   	 			  btnStyleByFontColor("bt2"); //按钮 字体样式修改
	              },
	              lastdays:function(){
	            	  var befroeDate = getBeforeDate(6);
	   	 			  var lastymd = getBeforeDate(0);
	   	 			  $("#startDate").val(befroeDate);
	   	 			  $("#endDate").val(lastymd);
	   	 			  btnStyleByFontColor("bt3"); //按钮 字体样式修改
	              },last30days:function(){
	            	  var befroeDate = getBeforeDate(29);
	   	 			  var lastymd = getBeforeDate(0);
	   	 			  $("#startDate").val(befroeDate);
	   	 			  $("#endDate").val(lastymd);
	   	 			  btnStyleByFontColor("bt4"); //按钮 字体样式修改
	              }
	                 }
	        $('.layui-btn').on('click', function(){
	            var othis = $(this), method = othis.data('method');
	            active[method] ? active[method].call(this, othis) : '';
	          }); 
		});
		
		
/***该方法为获取最近多少天的通用方法****/
	function getBeforeDate(n){
		    var n = n;
		     var d = new Date();
		     var year = d.getFullYear();
		     var mon=d.getMonth()+1;
		     var day=d.getDate();
		     if(day <= n){
		             if(mon>1) {
		                mon=mon-1;
		             }
		            else {
		              year = year-1;
	              mon = 12;
		              }
		            }
		           d.setDate(d.getDate()-n);
		           year = d.getFullYear();
		           mon=d.getMonth()+1;
		           day=d.getDate();
		      s = year+""+(mon<10?('0'+mon):mon)+""+(day<10?('0'+day):day);
		      return s;
		 }
/*****该方法为button点击时 修改button样式******/
	function btnStyleByFontColor(bt){
		for(var i = 1;i<6;i++)
		{
			var btId = "bt"+i;
			if(bt==btId){
				var div = document.getElementById(bt); 
				div.className = 'layui-btn'; 
				
			}else{
				var div=document.getElementById(btId);
				div.className='layui-btn layui-btn-primary';
			}
		}
		
	}
</script>
</html>